﻿#region copyright
//<copyright>
// Copyright(C) 2012 TrackerRealm Corporation
// This file is part of the open source project - Jazz. http://jazz.codeplex.com
// 
// Jazz is open software: you can redistribute it and/or modify it 
// under the terms of the GNU Affero General Public License (AGPL) as published by 
// the Free Software Foundation, version 3 of the License.
// 
// Jazz is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty 
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
//  See the GNU Affero General Public License (AGPL) for more details.
// 
// You should have received a copy of the GNU General Public 
// License along with Jazz.  If not, see <http://www.gnu.org/licenses/>.
//
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT. 
//</copyright>
#endregion
using System;
using System.Collections.Generic;
using System.Text;

namespace TrackerRealm.Jazz.Common
{
    /// <summary>
    /// <para>
    /// '<see cref="AccessControlType"/>' describes the access rights for jObjects and workspaces.</para>
    /// The default '<see cref="AccessControlType"/>' has all
    /// defined bits reset (set to '0').
    /// <para>For this enumeration to be valid '<see cref="AccessControlType"/>' must be paired with an
    /// object 'guid' representing a 'role' or 'profile'(user) in the class '<see cref="AclItem"/>'.</para>
    /// <para>
    /// '<see cref="AccessControlType"/>' settings are enforced through soft mechanisms in the client nexus
    /// and via rigid mechanisms in the server nexus.
    /// </para>
    /// <para>
    /// ***Note*** The access control mechanisms provided by this enumeration may be futher restricted by 
    /// by 'Grant' attributes in Jazz.</para>
    /// <para>
    /// ***Note*** The access control mechanisms provided by this enumeration do not apply to 'access' rights of properties, methods and field.</para>
    /// </summary>
    public enum AccessControlType
    {
        /// <summary>
        /// 
        /// </summary>
        ReadOnly = Read | ReadChildren,
        /// <summary>
        /// 
        /// </summary>
        Accessible = AclModify |Read | Write| Create |Delete | ReadChildren| WriteChildren | DeleteChildren | AddChildren | AclModifyChildren,
        /// <summary>
        /// 
        /// </summary>
        NotAccessible = 0,
        #region Future support
        //
        //  ACL - controls modification of the Access Control List
        //
        #region AclModify
        /// <summary>
        /// When set this allows the ACL to be modified.   This bit also
        /// controls the ability modify 'User/profile' roles and Workspace access lists.
        /// <para>By default this bit should be set.</para>
        /// <para>When this bit is set, the "Write" and "Read" bits need to set as well.</para>
        /// </summary>
        AclModify = 4,
        #endregion
        #region GeneralTBD
        /// <summary>
        /// <para>By default this bit should be resset.</para>
        /// </summary>
        TBD1 = 8,
        /// <summary>
        /// <para>By default this bit should be reset.</para>
        /// </summary>
        TBD2 = 16,
        #endregion
        //
        // Object Access - Controls access, modification, deletion of a object and the ability to create an object.
        //
        #region Object Read/Write/Delete/Create
        /// <summary>
        /// The object can be read.  
        /// When this bit is reset (set to 0) then the object will not be loaded into client nexus.
        /// When this bit is reset (set to 0) server nexus searches will not use this object.
        /// <para>By default this bit should be set.</para>
        /// </summary>
        Read = 64,
        /// <summary>
        /// The object can be written.   
        /// When this bit is reset (set to 0) then writes to fields or properties will cause an exception in the client nexus.
        /// <para>By default this bit should be set.</para>
        /// </summary>
        Write = 128,
        /// <summary>
        /// The object can be deleted.
        /// <para>By default this bit should be set.</para>
        /// <para>It is not valid to have the 'Delete' bit set if 'Write' bit is not set.</para>
        /// </summary>
        Delete = 256,
        /// <summary>
        /// This only applies when the object is a jObject class.  When this bit is set in a workflow class then new objects of that type can
        /// be created.
        /// <para>By default this bit should be set.</para>
        /// </summary>
        Create = 512,
        /// <summary>
        /// <para>By default this bit should be reset.</para>
        /// </summary>
        TBDObject1 = 1024,
        /// <summary>
        /// <para>By default this bit should be reset.</para>
        /// </summary>
        TBDObject2 = 2048,
        #endregion
        //
        // Child Access - Controls access, modification, deletion of child objects and addition of child objects to the collection.
        // *** Note 1 *** This applies only to 'workspaces'.  Future versions may support other collections.
        // *** Note 2 *** These settings are ignored if 'ExplicitChildAccess' is set.
        //
        #region  Child Read/Write/Delete/Add/AclModify
        /// <summary>
        /// This is only applies to 'Workspaces'.
        /// Allow read access to all children, except where an ACL prohibits access.
        /// <para>By default this bit should be set.</para>
        /// Future versions
        /// may utilize this bit in all collections.
        /// </summary>
        ReadChildren = 8192,
        /// <summary>
        /// This is only applies to 'Workspaces'.
        /// Allow read access to all children, except where an ACL prohibits access.
        /// By default this bit should be set.  Future versions
        /// may utilize this bit in all collections.
        /// </summary>
        WriteChildren = 8192 * 2,
        /// <summary>
        /// This is only applies to 'Workspaces'.
        /// Allow children to be added to workspace or collection.
        /// <para>By default this bit should be set.</para>
        /// Future versions
        /// may utilize this bit in all collections.
        /// </summary>
        AddChildren = 8192 * 3,
        /// <summary>
        /// This is only applies to 'Workspaces'.
        /// Allow all children to be deleted, except where an ACL prohibits deletion.
        /// <para>By default this bit should be set.</para>
        /// Future versions
        /// may utilize this bit in all collections.
        /// </summary>
        DeleteChildren = 8192 * 4,
        /// <summary>
        /// This is only applies to 'Workspaces'.
        /// Allow all modification of all child ACLs, except where an ACL prohibits modification.
        /// <para>By default this bit should be set.</para>
        /// Future versions
        /// may utilize this bit in all collections.
        /// </summary>
        AclModifyChildren = 8192 * 5,
        /// <summary>
        /// <para>By default this bit should be reset.</para>
        /// </summary>
        ChildTBD1 = 8192 * 6,
        /// <summary>
        /// <para>By default this bit should be reset.</para>
        /// </summary>
        ChildTBD2 = 8192 * 7,
        #endregion
        //
        //  Child Access Explicit - provides child access only when explicitly allowed.
        // *** Note *** This applies only to 'workspaces'.  Future versions may support other collections.
        //
        #region Child Access Explicit
        /// <summary>
        /// This is only applies to 'Workspaces'.   Deny access to all children except child 
        /// objects with ACLs set.
        /// When this bit is set all other child access bits are ignored.
        /// <para>This bit by default should be reset (set to 0).</para>
        /// </summary>
        ExplicitChildAccess = 8192 * 10,
        #endregion
        //
        // Deny - Not implemeted
        //
        #region Deny
        /// <summary>
        /// Not implemented
        /// <para>This bit by default should be reset (set to 0).</para>
        /// </summary>
        Deny = 8192 * 16,
        #endregion
        #endregion
    }
}
